package com.ruoyi.zhmk.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhmk.domain.ZhmkDoor;
import com.ruoyi.zhmk.service.IZhmkDoorService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 门禁设备Controller
 * 
 * @author sxl
 * @date 2021-06-15
 */
@Controller
@RequestMapping("/zhmk/door")
public class ZhmkDoorController extends BaseController
{
    private String prefix = "zhmk/door";

    @Autowired
    private IZhmkDoorService zhmkDoorService;

    @RequiresPermissions("zhmk:door:view")
    @GetMapping()
    public String door()
    {
        return prefix + "/door";
    }

    @RequiresPermissions("zhmk:door:view")
    @GetMapping("/doorIndex")
    public String doorIndex()
    {
        return prefix + "/doorIndex";
    }

    /**
     * 查询门禁设备列表
     */
    @RequiresPermissions("zhmk:door:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZhmkDoor zhmkDoor)
    {
        startPage();
        List<ZhmkDoor> list = zhmkDoorService.selectZhmkDoorList(zhmkDoor);
        return getDataTable(list);
    }

    /**
     * 导出门禁设备列表
     */
    @RequiresPermissions("zhmk:door:export")
    @Log(title = "门禁设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhmkDoor zhmkDoor)
    {
        List<ZhmkDoor> list = zhmkDoorService.selectZhmkDoorList(zhmkDoor);
        ExcelUtil<ZhmkDoor> util = new ExcelUtil<ZhmkDoor>(ZhmkDoor.class);
        return util.exportExcel(list, "门禁设备数据");
    }

    /**
     * 新增门禁设备
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存门禁设备
     */
    @RequiresPermissions("zhmk:door:add")
    @Log(title = "门禁设备", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZhmkDoor zhmkDoor)
    {
        return toAjax(zhmkDoorService.insertZhmkDoor(zhmkDoor));
    }

    /**
     * 修改门禁设备
     */
    @GetMapping("/edit/{doorId}")
    public String edit(@PathVariable("doorId") Long doorId, ModelMap mmap)
    {
        ZhmkDoor zhmkDoor = zhmkDoorService.selectZhmkDoorById(doorId);
        mmap.put("zhmkDoor", zhmkDoor);
        return prefix + "/edit";
    }

    /**
     * 修改保存门禁设备
     */
    @RequiresPermissions("zhmk:door:edit")
    @Log(title = "门禁设备", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZhmkDoor zhmkDoor)
    {
        return toAjax(zhmkDoorService.updateZhmkDoor(zhmkDoor));
    }

    /**
     * 删除门禁设备
     */
    @RequiresPermissions("zhmk:door:remove")
    @Log(title = "门禁设备", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zhmkDoorService.deleteZhmkDoorByIds(ids));
    }
}
